<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">首页</router-link> |
      <router-link to="/student">学生列表</router-link> ||
      <span v-if="isShow">欢迎：{{username}}</span>
      <button v-if="isShow" @click="logout">注销</button>
    </div>
    <router-view/>
  </div>
</template>
<script>
export default {
  data(){
    return{
      username:"",
      isShow:false
    }
  },
  watch:{
    '$route.path':function(){
      this.username=localStorage.getItem("usr");
      this.isShow=localStorage.getItem("usr");
    }
  },
  methods:{
    logout(){
      localStorage.clear();
      this.$router.push("/login");
    }
  }
}
</script>
